package com.prothink.service.impl;

import com.prothink.dao.JsCourseRecordDao;
import com.prothink.dao.JsLogDao;
import com.prothink.dao.JsProductDao;
import com.prothink.entity.JsCourseRecord;
import com.prothink.entity.JsLog;
import com.prothink.entity.JsProduct;
import com.prothink.service.JsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName : JsProductServiceImpl  //类名
 * @Description :   //描述
 * @Author : Zhang //作者
 * @Date: 11/21  14:25
 */
@Service
public class JsProductServiceImpl implements JsProductService {
    @Autowired
    private JsProductDao jsProductDao;
    @Autowired
    private JsCourseRecordDao jsCourseRecordDao;
    @Autowired
    private JsLogDao jsLogDao;

    @Override
    public List getProduct() {
        return jsProductDao.getProduct();
    }

    @Override
    public List<JsProduct> getProductJS(JsProduct jsProduct) {
        List<JsProduct> productJS = jsProductDao.getProductJS(jsProduct);
        if(productJS != null){
            JsLog jsLog = new JsLog("js_product","2",jsProduct.getUpdateId(),new Date(),"查看商品列表",1);
            jsLogDao.addLog(jsLog);
        }
        return productJS;
    }

    @Override
    public Boolean deleteProduct(Integer productId) {
        Boolean aBoolean = jsProductDao.deleteProduct(productId);
        if(aBoolean){
            JsLog jsLog = new JsLog("js_product","2",1,new Date(),"删除一件商品",1);
            jsLogDao.addLog(jsLog);
        }
        return aBoolean;
    }

    @Override
    public Boolean updProductSate(JsProduct jsProduct) {
        Boolean aBoolean = jsProductDao.updProductSate(jsProduct);
        if(aBoolean){
            JsLog jsLog = new JsLog("js_product","2",jsProduct.getUpdateId(),new Date(),"修改商品上/下架",1);
            jsLogDao.addLog(jsLog);
        }
        return aBoolean;
    }

    @Override
    public Boolean addProduct(JsProduct jsProduct) {
        Boolean aBoolean = jsProductDao.addProduct(jsProduct);
        if (aBoolean){
            JsCourseRecord jsCourseRecord = new JsCourseRecord();
            jsCourseRecord.setCourseId(jsProduct.getProductId());
            jsCourseRecord.setLaunchId(jsProduct.getCreateId());
            jsCourseRecord.setApplyDate(new Date());
            jsCourseRecord.setResult("未审核");
            jsCourseRecordDao.addRecord(jsCourseRecord);

            JsLog jsLog = new JsLog("js_product","2",jsProduct.getUpdateId(),new Date(),"添加一件商品",1);
            jsLogDao.addLog(jsLog);
        }
        return aBoolean;
    }

    @Override
    public Boolean updateProduct(JsProduct jsProduct) {
        Boolean aBoolean = jsProductDao.updateProduct(jsProduct);
        if(aBoolean){
            JsLog jsLog = new JsLog("js_product","2",jsProduct.getUpdateId(),new Date(),"修改商品列表",1);
            jsLogDao.addLog(jsLog);
        }
        return aBoolean;
    }

    @Override
    public JsProduct getProductByshopId(Integer shopId) {
        JsProduct product = jsProductDao.getProductByshopId(shopId);
        return product;
    }
}
